<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>运行时 API 示例 | My Awesome Project</title>
    <meta name="description" content="A VitePress Site">
    <meta name="generator" content="VitePress v2.0.0-alpha.11">
    <link rel="preload stylesheet" href="/vitepress-demo1/assets/style.DgU-1wCV.css" as="style">
    <link rel="preload stylesheet" href="/vitepress-demo1/vp-icons.css" as="style">
    
    <script type="module" src="/vitepress-demo1/assets/app.Ce8EqjSF.js"></script>
    <link rel="preload" href="/vitepress-demo1/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/vitepress-demo1/assets/chunks/theme.BFOxXw9B.js">
    <link rel="modulepreload" href="/vitepress-demo1/assets/chunks/framework.DchbbUd2.js">
    <link rel="modulepreload" href="/vitepress-demo1/assets/api-examples.md.NyTVnued.lean.js">
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-304c8b69><!--[--><!--]--><!--[--><span tabindex="-1" data-v-fcbfc0e0></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-fcbfc0e0>Skip to content</a><!--]--><!----><header class="VPNav" data-v-304c8b69 data-v-d5bf7c8e><div class="VPNavBar" data-v-d5bf7c8e data-v-cb5e22fa><div class="wrapper" data-v-cb5e22fa><div class="container" data-v-cb5e22fa><div class="title" data-v-cb5e22fa><div class="VPNavBarTitle has-sidebar" data-v-cb5e22fa data-v-d4488dd0><a class="title" href="/vitepress-demo1/" data-v-d4488dd0><!--[--><!--]--><!----><span data-v-d4488dd0>My Awesome Project</span><!--[--><!--]--></a></div></div><div class="content" data-v-cb5e22fa><div class="content-body" data-v-cb5e22fa><!--[--><!--]--><div class="VPNavBarSearch search" data-v-cb5e22fa><!----></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-cb5e22fa data-v-020be4db><span id="main-nav-aria-label" class="visually-hidden" data-v-020be4db> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/vitepress-demo1/" tabindex="0" data-v-020be4db data-v-815115f5><!--[--><span data-v-815115f5>Home</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/vitepress-demo1/markdown-examples.html" tabindex="0" data-v-020be4db data-v-815115f5><!--[--><span data-v-815115f5>Examples</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-cb5e22fa data-v-3f90c1a5><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-3f90c1a5 data-v-be9742d9 data-v-b4ccac88><span class="check" data-v-b4ccac88><span class="icon" data-v-b4ccac88><!--[--><span class="vpi-sun sun" data-v-be9742d9></span><span class="vpi-moon moon" data-v-be9742d9></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-cb5e22fa data-v-ef6192dc data-v-a1a7286e><!--[--><a class="VPSocialLink no-icon" href="https://github.com/vuejs/vitepress" aria-label="github" target="_blank" rel="me noopener" data-v-a1a7286e data-v-32d78712><span class="vpi-social-github"></span></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-cb5e22fa data-v-f953d92f data-v-d8fae6e2><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-d8fae6e2><span class="vpi-more-horizontal icon" data-v-d8fae6e2></span></button><div class="menu" data-v-d8fae6e2><div class="VPMenu" data-v-d8fae6e2 data-v-fcd1d7a8><!----><!--[--><!--[--><!----><div class="group" data-v-f953d92f><div class="item appearance" data-v-f953d92f><p class="label" data-v-f953d92f>Appearance</p><div class="appearance-action" data-v-f953d92f><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-f953d92f data-v-be9742d9 data-v-b4ccac88><span class="check" data-v-b4ccac88><span class="icon" data-v-b4ccac88><!--[--><span class="vpi-sun sun" data-v-be9742d9></span><span class="vpi-moon moon" data-v-be9742d9></span><!--]--></span></span></button></div></div></div><div class="group" data-v-f953d92f><div class="item social-links" data-v-f953d92f><div class="VPSocialLinks social-links-list" data-v-f953d92f data-v-a1a7286e><!--[--><a class="VPSocialLink no-icon" href="https://github.com/vuejs/vitepress" aria-label="github" target="_blank" rel="me noopener" data-v-a1a7286e data-v-32d78712><span class="vpi-social-github"></span></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-cb5e22fa data-v-6bee1efd><span class="container" data-v-6bee1efd><span class="top" data-v-6bee1efd></span><span class="middle" data-v-6bee1efd></span><span class="bottom" data-v-6bee1efd></span></span></button></div></div></div></div><div class="divider" data-v-cb5e22fa><div class="divider-line" data-v-cb5e22fa></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-304c8b69 data-v-6c0451ca><div class="container" data-v-6c0451ca><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-6c0451ca><span class="vpi-align-left menu-icon" data-v-6c0451ca></span><span class="menu-text" data-v-6c0451ca>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-6c0451ca data-v-92b7576c><button data-v-92b7576c>Return to top</button><!----></div></div></div><aside class="VPSidebar" data-v-304c8b69 data-v-606f96d3><div class="curtain" data-v-606f96d3></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-606f96d3><span class="visually-hidden" id="sidebar-aria-label" data-v-606f96d3> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-a84b7c21><section class="VPSidebarItem level-0 has-active" data-v-a84b7c21 data-v-6b36a2fd><div class="item" role="button" tabindex="0" data-v-6b36a2fd><div class="indicator" data-v-6b36a2fd></div><h2 class="text" data-v-6b36a2fd>Examples</h2><!----></div><div class="items" data-v-6b36a2fd><!--[--><div class="VPSidebarItem level-1 is-link" data-v-6b36a2fd data-v-6b36a2fd><div class="item" data-v-6b36a2fd><div class="indicator" data-v-6b36a2fd></div><a class="VPLink link link" href="/vitepress-demo1/markdown-examples.html" data-v-6b36a2fd><!--[--><p class="text" data-v-6b36a2fd>Markdown Examples</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-6b36a2fd data-v-6b36a2fd><div class="item" data-v-6b36a2fd><div class="indicator" data-v-6b36a2fd></div><a class="VPLink link link" href="/vitepress-demo1/api-examples.html" data-v-6b36a2fd><!--[--><p class="text" data-v-6b36a2fd>Runtime API Examples</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-304c8b69 data-v-2652e39a><div class="VPDoc has-sidebar has-aside" data-v-2652e39a data-v-d668f7cc><!--[--><!--]--><div class="container" data-v-d668f7cc><div class="aside" data-v-d668f7cc><div class="aside-curtain" data-v-d668f7cc></div><div class="aside-container" data-v-d668f7cc><div class="aside-content" data-v-d668f7cc><div class="VPDocAside" data-v-d668f7cc data-v-cb998dce><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-cb998dce data-v-c8b19031><div class="content" data-v-c8b19031><div class="outline-marker" data-v-c8b19031></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-c8b19031>On this page</div><ul class="VPDocOutlineItem root" data-v-c8b19031 data-v-b7d7ef80><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-cb998dce></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-d668f7cc><div class="content-container" data-v-d668f7cc><!--[--><!--]--><main class="main" data-v-d668f7cc><div style="position:relative;" class="vp-doc _vitepress-demo1_api-examples" data-v-d668f7cc><div><h1 id="运行时-api-示例" tabindex="-1">运行时 API 示例 <a class="header-anchor" href="#运行时-api-示例" aria-label="Permalink to “运行时 API 示例”">​</a></h1><p>本页面展示了 VitePress 提供的一些运行时 API 的用法。</p><p>主要的 <code>useData()</code> API 可用于访问当前页面的站点、主题和页面数据。它适用于 <code>.md</code> 和 <code>.vue</code> 文件：</p><div class="language-md"><button title="Copy Code" class="copy"></button><span class="lang">md</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;script setup&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">import { useData } from &#39;vitepress&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">const { theme, page, frontmatter } = useData()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/script&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">## 结果</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">### 主题数据</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;pre&gt;{{ theme }}&lt;/pre&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">### 页面数据</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;pre&gt;{{ page }}&lt;/pre&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">### 页面 Frontmatter</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;pre&gt;{{ frontmatter }}&lt;/pre&gt;</span></span></code></pre></div><h2 id="结果" tabindex="-1">结果 <a class="header-anchor" href="#结果" aria-label="Permalink to “结果”">​</a></h2><h3 id="主题数据" tabindex="-1">主题数据 <a class="header-anchor" href="#主题数据" aria-label="Permalink to “主题数据”">​</a></h3><pre>{
  &quot;nav&quot;: [
    {
      &quot;text&quot;: &quot;Home&quot;,
      &quot;link&quot;: &quot;/&quot;
    },
    {
      &quot;text&quot;: &quot;Examples&quot;,
      &quot;link&quot;: &quot;/markdown-examples&quot;
    }
  ],
  &quot;sidebar&quot;: [
    {
      &quot;text&quot;: &quot;Examples&quot;,
      &quot;items&quot;: [
        {
          &quot;text&quot;: &quot;Markdown Examples&quot;,
          &quot;link&quot;: &quot;/markdown-examples&quot;
        },
        {
          &quot;text&quot;: &quot;Runtime API Examples&quot;,
          &quot;link&quot;: &quot;/api-examples&quot;
        }
      ]
    }
  ],
  &quot;socialLinks&quot;: [
    {
      &quot;icon&quot;: &quot;github&quot;,
      &quot;link&quot;: &quot;https://github.com/vuejs/vitepress&quot;
    }
  ]
}</pre><h3 id="页面数据" tabindex="-1">页面数据 <a class="header-anchor" href="#页面数据" aria-label="Permalink to “页面数据”">​</a></h3><pre>{
  &quot;title&quot;: &quot;运行时 API 示例&quot;,
  &quot;description&quot;: &quot;&quot;,
  &quot;frontmatter&quot;: {
    &quot;outline&quot;: &quot;deep&quot;
  },
  &quot;headers&quot;: [],
  &quot;relativePath&quot;: &quot;api-examples.md&quot;,
  &quot;filePath&quot;: &quot;api-examples.md&quot;
}</pre><h3 id="页面-frontmatter" tabindex="-1">页面 Frontmatter <a class="header-anchor" href="#页面-frontmatter" aria-label="Permalink to “页面 Frontmatter”">​</a></h3><pre>{
  &quot;outline&quot;: &quot;deep&quot;
}</pre><h2 id="更多" tabindex="-1">更多 <a class="header-anchor" href="#更多" aria-label="Permalink to “更多”">​</a></h2><p>查看文档以获取 <a href="https://vitepress.dev/reference/runtime-api#usedata" target="_blank" rel="noreferrer">完整的运行时 API 列表</a>。</p></div></div></main><footer class="VPDocFooter" data-v-d668f7cc data-v-1bcd8184><!--[--><!--]--><!----><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-1bcd8184><span class="visually-hidden" id="doc-footer-aria-label" data-v-1bcd8184>Pager</span><div class="pager" data-v-1bcd8184><a class="VPLink link pager-link prev" href="/vitepress-demo1/markdown-examples.html" data-v-1bcd8184><!--[--><span class="desc" data-v-1bcd8184>Previous page</span><span class="title" data-v-1bcd8184>Markdown Examples</span><!--]--></a></div><div class="pager" data-v-1bcd8184><!----></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"api-examples.md\":\"NyTVnued\",\"index.md\":\"D_-nbSqo\",\"markdown-examples.md\":\"DnMskSDD\",\"readme.md\":\"BE463FpB\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"My Awesome Project\",\"description\":\"A VitePress Site\",\"base\":\"/vitepress-demo1/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"nav\":[{\"text\":\"Home\",\"link\":\"/\"},{\"text\":\"Examples\",\"link\":\"/markdown-examples\"}],\"sidebar\":[{\"text\":\"Examples\",\"items\":[{\"text\":\"Markdown Examples\",\"link\":\"/markdown-examples\"},{\"text\":\"Runtime API Examples\",\"link\":\"/api-examples\"}]}],\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/vuejs/vitepress\"}]},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false,\"additionalConfig\":{}}");</script>
    
  </body>
</html>